package opera;

import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DickYang
 * Date: 2023-05-28
 * Time: 10:40
 */
public class BrrowOperation implements IOPeration {
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入借阅的图书名:");
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.getUserSize(); i++) {

            if (name.equals(bookList.getBooks(i).getName()) && !bookList.getBooks(i).isBrrowed()) {
                System.out.println("借阅成功!");
                bookList.getBooks(i).setBrrowed(true);
                return;
            }else if (name.equals(bookList.getBooks(i).getName()) && bookList.getBooks(i).isBrrowed()){
                System.out.println("已被借阅!!");
                return;
            }
        }
        System.out.println("查无此书！");
    }
}
